/** 
 *  \file I3Id.h
 *  \brief This file defines an i3 identifier.  It mainly acts
 *  as a wraparound the original i3 ID.
 */
#ifndef NEW_I3_ID_H
#define NEW_I3_ID_H 1

#include <string>

#ifndef _WIN32
	#include <netdb.h>
#endif

extern "C" {
    #include "i3.h"
}
using namespace std;

#define I3_ID_LEN 32 
//XXX: Verify ID_LEN
#define I3_ID_LEN_BITS 256
#define PREFIX_LEN 8

#define DEFAULT_PREFIX_LEN 5

#define I3_ID_TYPE_PUBLIC 0x10
#define I3_ID_TYPE_PRIVATE 0x20

/** For buffers used to print an I3Id */
#define MAX_ID_PRINT_LEN    50


/**
  * This class encapsulates an I3 id.
  * Since I3 uses Chord, this class has the same fields as chordID
  * defined in chord/chord.h .
  */
class I3Id {
private:

    unsigned char toDigit(char ch);
    void setIdType(char idType);

public:
    string idStr;
    
    ID id;
    
    I3Id();
    I3Id(ID *valId);
    I3Id(string idStr, char idType);
    static I3Id* generateI3Id(string str, char idType);
    static string convertIdToStr(ID id);

    char* toString(char *tmpStr);

    bool isPublic();
    bool isPrivate();
    ID* getID();

    static void hash_URL_on_ID(const char* url, ID *id);
    static void get_random_ID(ID *id);
    static void gen_private_ID(ID *id);
   
    static void convertStr2I3Id (const char *idStr, ID *id);
};

#endif
